package com.rxt.thermopro.ex

import android.app.Activity
import android.graphics.Bitmap
import android.util.Log
import com.rxt.thermopro.app.AppContext
import java.io.FileOutputStream


object ShotEx {

    fun screenShotAndShare(activity: Activity) {
        val filepath =
            AppContext.get().cacheDir.absolutePath + "/screen_shot_${System.currentTimeMillis()}"
        var bitmap: Bitmap? = null
        try {
            //截图
            activity.window.decorView.isDrawingCacheEnabled = true
            bitmap = activity.window.decorView.drawingCache

            //保存图片
            val fos = FileOutputStream(filepath)
            bitmap.compress(Bitmap.CompressFormat.PNG, 50, fos)


        } catch (e: Exception) {
            Log.e("whh0914", "111屏幕截图出现异常：$e")
        }
    }

}